"""
Render VersionInfo.cpp with current module version
"""
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")

# Slang version is major.minor.micro
# We strip away any sub-version numbers after the first 3 (e.g. remove a potential `.bcr.1`)
[
    SLANG_VERSION_MAJOR,
    SLANG_VERSION_MINOR,
    SLANG_VERSION_MICRO,
] = module_version().split(".")[:3]

expand_template(
    name = "VersionInfo",
    out = "VersionInfo.cpp",
    substitutions = {
        "@SLANG_VERSION_MAJOR@": SLANG_VERSION_MAJOR,
        "@SLANG_VERSION_MINOR@": SLANG_VERSION_MINOR,
        "@SLANG_VERSION_PATCH@": SLANG_VERSION_MICRO,
        # Don't bother extracting the git hash
        "@SLANG_VERSION_HASH@": "GIT_HASH_NOT_PROVIDED",
    },
    template = "VersionInfo.cpp.in",
    visibility = ["//:__subpackages__"],
)
